package main

import "strconv"

func validSegment(seg string) bool {
	if len(seg) == 0 || len(seg) > 3 {
		return false
	}
	if len(seg) > 1 && seg[0] == '0' {
		return false
	}
	val, err := strconv.ParseInt(seg, 10, 64)
	if err != nil {
		return false
	}
	return val <= 255
}

func restoreIpAddresses(s string) []string {
	var result []string
	size := len(s)
	for i := 1; i < size; i++ {
		seg1 := s[0:i]
		if !validSegment(seg1) {
			continue
		}
		for j := i + 1; j < size && j <= i+3; j++ {
			seg2 := s[i:j]
			if !validSegment(seg2) {
				continue
			}
			for k := j + 1; k < size && k <= j+3; k++ {
				seg3 := s[j:k]
				seg4 := s[k:size]
				if !validSegment(seg3) || !validSegment(seg4) {
					continue
				}
				result = append(result, seg1+"."+seg2+"."+seg3+"."+seg4)
			}
		}
	}
	return result
}

func main() {
	result := restoreIpAddresses("2552551110")
	println(result)
}
